﻿using DataScripter.Database;
using DataScripter.Scripting;
using DataScripter.Scripting.InputSources;
using DataScripter.Scripting.Output;
using DataScripter.Scripting.Output.Sql.SqlServer;
using DataScripter.Scripting.OutputDestinations;
using DataScripter.Scripting.ScriptDefinitions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace DataScripter.UnitTests.EngineTests.Script
{
    [TestClass]
    public class WhenEngineIsScriptingToMemory
    {
        private readonly Engine _engine;
        private readonly IScriptResult _scriptResult;
        private readonly SqlServerScriptOptions _options;

        public WhenEngineIsScriptingToMemory()
        {
            Mock<IDatabaseStructure> structureMock = new Mock<IDatabaseStructure>();
            Mock<IDataProducer> dataProducerMock = new Mock<IDataProducer>();
            Mock<IOutputProducer> producerMock = new Mock<IOutputProducer>();

            _engine = new Engine();
            IInputSource inputSource = new SqlServerInputSource("", _engine);
            _engine.RegisterType(inputSource);
            IOutputDestination outputDestination = new FileOutputDestination("", _engine);
            _engine.RegisterType(outputDestination);

            _engine.RegisterType(structureMock.Object);
            inputSource.RegisterType(dataProducerMock.Object);
            outputDestination.RegisterType(producerMock.Object);

            IScriptDefinition engineMock = new ScriptDefinition("", _engine);
            _engine.RegisterType(engineMock);


            _options = new SqlServerScriptOptions(SqlScriptType.Insert)
            {
                ScriptOutputType = ScriptOutputType.Memory
            };
            _scriptResult = _engine.Script(_options);
        }

        [TestMethod]
        public void ScriptResultShouldNotBeNull()
        {
            Assert.IsNotNull(_scriptResult);
        }

        [TestMethod]
        public void OutputShouldNotBeNull()
        {
            Assert.IsNotNull(_scriptResult.Output);
        }

    }
}
